package com.gxa.meiye.admin.platform.controller;

import com.gxa.meiye.admin.platform.pojo.vo.*;
import com.gxa.meiye.admin.platform.service.FinanceManageServcie;
import com.gxa.meiye.core.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api
@RestController
@RequestMapping("/platform/financemanage")
public class FinancemanageController {
    @Resource
    private FinanceManageServcie financeManageServcie;
    @ApiOperation("财务管理（点击财务管理渲染）")
    @GetMapping("/financemanage/queryAll")
    public Map queryAll(){
        List<FinanceManageVo> financeManageVos = this.financeManageServcie.queryAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(financeManageVos);
        jsonResult.setMsg("查询成功");
        return jsonResult.getMap();
    }
    @ApiOperation("搜索财务管理（状态为0-8）")
    @PostMapping("/financemanage/selectAll")
    public Map selectAll(@RequestBody SelectFinanceVo selectFinanceVo){
        List<FinanceManageVo> financeManageVos;
        if(selectFinanceVo.getStatus() == 0){
            financeManageVos = this.financeManageServcie.selectAll0(selectFinanceVo.getStatus(), selectFinanceVo.getBegintime(), selectFinanceVo.getEndtime(), selectFinanceVo.getTempall());
        }else{
            financeManageVos =this.financeManageServcie.selectAll(selectFinanceVo.getStatus(), selectFinanceVo.getBegintime(), selectFinanceVo.getEndtime(), selectFinanceVo.getTempall());
        }
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(financeManageVos);
        jsonResult.setMsg("查询成功");
        return jsonResult.getMap();
    }
    @ApiOperation("立即结算")
    @PostMapping("/financemanage/updateStatus")
    public Map updateStatus(@RequestBody UpdateServiceVo updateServiceVo){
        if(updateServiceVo.getStatus() == 4) {
            this.financeManageServcie.updateStatus(updateServiceVo.getStatus(),updateServiceVo.getOrder_num());
        }
        List<FinanceManageVo> financeManageVos = this.financeManageServcie.queryAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(financeManageVos);
        jsonResult.setMsg("修改成功");
        return jsonResult.getMap();
    }
}
